$(document).ready(function () {
    var global_max_index = 0;
    var current_page = 1;
    $.get('/articles_list',
        function (data,status) {
        if(status == 'success')
            var index_page_json = JSON.parse(data);
            global_max_index = index_page_json.max_index;
            //console.log(index_page_json);
            if(global_max_index>0){
                $.get('/article/1',
                    function (data,status) {
                        var html_content = document.getElementById('list_content');
                        $("#list_content").html(data)
                        $('#next_page').css("background-color","#23c6c8");
                        $('#pre_page').css("background-color","#666666");
                    })
            }
        });
    $('#first_page').click(function () {
        $.get('/article/1',
            function (data,status) {
                $("#list_content").html(data);
                $('#page_index').text('1');
                $('#pre_page').css("background-color","#666666");
                $('#next_page').css("background-color","#23c6c8");
            });
    });
    $('#last_page').click(function () {
        $.get('/article/'+global_max_index,
            function (data,status) {
                $('#page_index').text(global_max_index);
                $("#list_content").html(data);
                $('#next_page').css("background-color","#666666");
                $('#pre_page').css("background-color","#23c6c8");
            });
    });
    $('#next_page').click(function () {
        current_page++;
        current_page = current_page>global_max_index?global_max_index:current_page;
        if(current_page == global_max_index)
        {
            $('#next_page').css("background-color","#666666");
            $('#pre_page').css("background-color","#23c6c8");
        }
        else
        {
            $('#next_page').css("background-color","#23c6c8");
            $('#pre_page').css("background-color","#23c6c8");
        }

            $.get('/article/'+current_page,
            function (data,status) {
                $("#list_content").html(data);
                $('#page_index').text(current_page);
            });


    });
    $('#pre_page').click(function () {
        current_page--;
        current_page = current_page<1?1:current_page;
        $.get('/article/'+current_page,
                function (data,status) {
                    $("#list_content").html(data);
                    $('#page_index').text(current_page);
                });
        if(current_page == 1)
        {
            $('#next_page').css("background-color","#23c6c8");
            $('#pre_page').css("background-color","#666666");
        }
        else
        {
            $('#next_page').css("background-color","#23c6c8");
            $('#pre_page').css("background-color","#23c6c8");
        }
    });

});
function get_article_byId(data) {
    //console.log(data);
    var page = window.parent.document.getElementById("ifd");
    page.setAttribute('src','/article/'+data.id+'.html');
}

function update_article_byId(data) {
    console.log(data)

}